package org.darcy.youchat.activity.login;

import android.content.Intent;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;

import org.darcy.youchat.activity.BaseActivity;
import org.darcy.youchat.activity.MainActivity;
import org.darcy.youchat.databinding.ActivitySplashBinding;
import org.darcy.youchat.nimsdk.NimAccountSDK;
import org.darcy.youchat.utils.UIUtils;


/**
 * 欢迎界面
 */
public class SplashActivity extends BaseActivity {

    /**
     * 视图绑定类 对象
     */
    private ActivitySplashBinding binding;

    public void login() {
        startActivity(new Intent(this, LoginActivity.class));
    }

    public void register() {
        UIUtils.showToast("暂不支持");
    }

    @Override
    public void init() {
        if (canAutoLogin()) {
            //登录到主界面
            startActivity(new Intent(this, MainActivity.class));
            finish();
        }
    }

    @Override
    public void initView() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        binding = ActivitySplashBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btnLogin.setOnClickListener(v -> {
            login();
        });
        binding.btnRegister.setOnClickListener(v -> {
            register();
        });
    }

    /**
     * 判断是否可以自动登录
     */
    public boolean canAutoLogin() {
        String account = NimAccountSDK.getUserAccount();
        String token = NimAccountSDK.getUserToken();
        return !TextUtils.isEmpty(account) && !TextUtils.isEmpty(token);
    }

}
